{template "common/header"}	
<ul class="nav nav-tabs">
  <li {if $op == 'list'}class="active"{/if}>
     <a href="{php echo $this->createWebUrl('card',array('op'=>'list'))}" >兑课券列表</a>
  </li>
  <li {if $op == 'post'}class="active"{/if}>
     <a href="{php echo $this->createWebUrl('card',array('op'=>'post'))}" >{if empty($info['id'])}创建兑课券{else}修改兑课券{/if}</a>
  </li>
</ul>
<style type="text/css">
	.xh-toast-block{ min-width: 300px; position:fixed; z-index: 9999; font-size: 18px; color: #e7e7e7; padding: 10px 20px; background: rgba(0,0,0,0.7); left: 50%; top: 50%; line-height: 40px; border-radius: 10px; text-align: center; margin-top: -30px; margin-left: -150px; }
	.modeladd li{
		padding-top: 5px;
		padding-bottom: 5px;
		list-style: none;
		width: 100%;
		float: left;
	}
</style>
{if $op == 'list'}
<div class="row clearfix" >
<div class="col-md-12 column">
		<div class="list-group">
			<p  class="list-group-item " style="background-color: #D9EDF7" >兑课券管理</p>
			<div active="list-group-item" style="border:1px solid #cecece;">
				<table class="table table-hover table-bordered" style="margin-top:25px;width:98%" align="center">
					<thead>
						<tr>
							<th>ID</th>
							<th>抵用金额</th>
							<th>兑换币数量</th>
							<th>有效期</th>
							<th>使用条件</th>
							<th>状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						{loop $list $row}
						<tr>
							<td>{$row['id']}</td>
							<td>{$row['price']}</td>
							<td>{$row['need']}</td>
							<td>{$row['end_time']}</td>
							<td>满{$row['condition']}元可使用</td>
							<td style="width:15%"><div class="btn {if $row['status'] == 0}btn-danger{else}btn-info{/if}" data="{$row['id']}" onclick="cardstatus(this)">{if $row['status'] == 0}不显示{elseif $row['status'] == 1}显示{/if}</div></td>
							<td>
				                <a href="{php echo $this->createWebUrl('card',array('op'=>'post','id'=>$row['id']))}" class="btn btn-info">编辑</a>
								<a href="{php echo $this->createWebUrl('card',array('op'=>'delete','id'=>$row['id']))}" class="btn btn-danger">删除</a>
				            </td>
						</tr>
						{/loop}
					</tbody>
				</table>
			</div>
		{$page}
	</div>
</div>
</div>
<script type="text/javascript">
  	function cardstatus(obj){
  		var obj = $(obj);
  		var id = obj.attr('data');
  		if(obj.hasClass('btn-danger')){
  			var sta = 1;
  		}else{
  			var sta = 0;
  		}
  		$.ajax({
  			type:'post',
  			url:"{php echo $this->createWebUrl('card',array('op'=>'changestatus'))}",
  			data:{id:id,sta:sta},
  			success:function(res){
  				var res = JSON.parse(res);
  				if(res.success == 1){
  					if(sta == 1){
  						obj.removeClass('btn-danger');
  						obj.addClass('btn-info');
  						obj.html('显示');
  					}else{
  						obj.removeClass('btn-info');
  						obj.addClass('btn-danger');
  						obj.html('不显示');
  					}
  				}else{
  					alert(res.mess);
  				}
  			}
  		});
  	}
  </script>
{elseif $op == 'post'}
<div class="list-group">
<p href="#" class="list-group-item" style="background-color: #D9EDF7;border:1px solid #D9EDF7;color:#31708F">创建兑课券</p>
<div active="list-group-item " style="border:1px solid #cecece">
	<form action="" method="post" class="form-horizontal" >
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color:red">*</span>兑课券金额</label>
			<div class="col-sm-10">
				<input type="text" name="price" value="{$info['price']}" placeholder="例如：50.50，保留小数点后两位，最大值不超过50000"   class="form-control" style="width:98%"/>
				<span class="help-block">兑课券抵扣金额</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color:red">*</span>兑课券使用条件</label>
			<div class="col-sm-10">
				<input type="number" name="condition" value="{$info['condition']}" placeholder="例如：200,表示订单金额超过200才能使用"    class="form-control" style="width:98%"/>
				<span class="help-block">订单总额超出设定值才可使用</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color:red">*</span>兑换需要兑换币数量</label>
			<div class="col-sm-10">
				<input type="number" name="need" value="{$info['need']}" placeholder="请填写整数"    class="form-control" style="width:98%"/>
				<span class="help-block">兑换兑课券需要消耗的兑换币的数量</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">兑课券有效期</label>
			<div class="col-sm-10">
				<input type="number" name="end_time" value="{$info['end_times']}"  placeholder="例如：30，表示兑换后30天内可使用，超出后显示已过期"  class="form-control" style="width:98%"/>
				<span class="help-block">领取兑课券后，在有效期内可以使用，单位为天，默认为30天</span>
			</div>
		</div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">兑课券使用描述</label>
			<div class="col-sm-10">
				<input type="text" name="desc" value="{$info['desc']}" placeholder="例如：单词购买课程满XX元即可使用，最多50个字符" class="form-control" style="width:98%" maxlength="50"/>
				<span class="help-block">设置兑课券使用说明</span>
			</div>
		</div>
		<!--<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label"><span style="color:red">*</span>价格</label>
			<div class="col-sm-10">
				<input type="text" name="price" value="{$info['price']}" onfocus="this.value=''"
						onblur= "if( ! /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.value) && Number(this.value)>=50000){alert('只能输入数字，小数点后只能保留两位');this.value='';}" class="form-control" style="width:98%"/>
			</div>
			<span style='color: #cecece;font-size: 14px;margin-left: 282px'>整包价格/听课券张数所得单张价格请勿超过 单张购买时价格</span>
		</div>-->
		<div class="form-group ">
			<label  class="col-sm-2 control-label">状态</label>
			<div class=" col-sm-10" style="padding-left:25px">
				<label class="radio-inline">
					<input type="radio" name="status"  value='0' title="不显示" {if empty($info['id'])}checked{/if} {if $info['status'] == '0'}checked{/if}> 不显示
				 </label>
				<label class="radio-inline">
					<input type="radio" name="status"  value='1' title="显示" {if $info['status'] == '1'}checked{/if}> 显示
				</label>
				<span class="help-block">若不选择，默认为不显示</span>
			</div>
	    </div>
		<div class="form-group" style="margin-top:25px">
			<label  class="col-sm-2 control-label">排序值</label>
			<div class="col-sm-10">
				<input type="number" name="order" value="{$info['order']}"   class="form-control" style="width:98%"/>
				<span class="help-block">排序值，数值越大，排序越靠前</span>
			</div>
		</div>
		<input type="hidden" name="token" value="{$_W['token']}">
		<div style="float: right;margin:10px">
			<input type="submit" name="submit" value="保存设置" class="btn btn-info" onclick="return check()">
		</div>
		<div style="clear: both;"></div>
	</form>
</div>
</div>
<script>
	function check(){
	    var flag = true;
		if($('input[name="price"]').val() == '' || ! /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test($('input[name="price"]').val()) || Number($('input[name="price"]').val())>=50000){
			flag = false;
            xhToast('请设置正确的兑课券金额');
            return flag;
		}
		if($('input[name="condition"]').val() == ''){
            flag = false;
            xhToast('请设置使用条件');
            return flag;
		}
		if($('input[name="need"]').val() == ''){
            flag = false;
            xhToast('请设置兑换条件');
            return flag;
		}
	    return flag;
	}
    //公用提示窗
    function xhToast(_text){
        $('body').append("<div class='xh-toast-block'>"+_text+"</div>");
        setTimeout(function(){
            $('.xh-toast-block').remove();
        },2000);
    }
</script>
{/if}
{template "common/footer"}